home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************
- *
- * manyRIS.c
- *
- * Program to generate and write many images of many different sizes
- * as RISs, then read them back and verify their correctness.
- *
- * User supplies number of images and file name.
- *
- * NOTE: Currently does not test imcomp compression.
- *
- ******************************************************************/
-
- #include "df.h"
- #include <stdio.h>
- #ifdef __STDC__
- #include <stdlib.h>
- #else
- #include <malloc.h>
- #endif
-
-
- #define NUM_PAL 2
- #define PAL_SIZE 768
- #define DIM_MAX 100.0
- #define TRUE 1
- #define FALSE 0
-
- static xsizes[] = {100, 50, 20, 10, 99, 52, 23, 100, 17, 51 };
- static ysizes[] = {100, 50, 20, 10, 100, 100, 100, 20, 23, 51 };
- static palflags[] = { 0, 1, 0, 0, 0, 1, 1, 0, 0, 0 };
-
- typedef struct {
- int xdim, ydim;
- char *img;
- char *pal;
- int comp;
- } record;
-
- record *rec;
-
- char *randArray();
- void putImages();
- void checkImages();
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int i, numImages;
- char *fname;
-
- if (argc < 3) {
- puts("Usage :");
- printf("\t%s <number of images> <file name>\n", argv[0]);
- exit(1);
- }
-
- numImages = atoi(argv[1]);
- fname = argv[2];
- printf("Test invoked with %d images and file %s.\n", numImages, fname);
-
- srand(getpid());
- rec = (record *) malloc(numImages*sizeof(record));
- if (rec == NULL) {
- puts("--Calloc error");
- exit(1);
- }
-
- printf("\n===== Now putting images ==============\n\n");
- putImages(fname, numImages);
- printf("\n\n===== Now checking images ==============\n\n");
- checkImages(fname, numImages);
- }
-
- void
- putImages(fname, numImages)
- char *fname;
- int numImages;
- {
- int i, ret;
- int firstImage = TRUE;
-
- for (i=0;i<numImages;i++) {
- printf("Putting image %d.\n", i);
-
- rec[i].xdim = xsizes[i%10];
- rec[i].ydim = ysizes[i%10];
- rec[i].img = randArray(rec[i].xdim * rec[i].ydim);
- rec[i].comp = rndCompress(rec[i].xdim * rec[i].ydim);
-
- if (rec[i].comp == DFTAG_IMC) /* REMOVE THIS WHEN IMCOMP IS FIXED */
- rec[i].comp = DFTAG_RLE;
-
- printf("Image %d stats : %d * %d, %d compress scheme.\n",
- i, rec[i].xdim, rec[i].ydim, rec[i].comp);
-
- if (palflags[i%10] == 1) {
- rec[i].pal = randArray(256);
- printf("Palette included\n");
- }else {
- rec[i].pal = NULL;
- printf("Palette not included\n");
- }
- ret = DFR8setpalette(rec[i].pal);
- printf("DFR8setpalette return %d.\n", ret);
-
- if (firstImage) {
- ret = DFR8putimage(fname, rec[i].img, rec[i].xdim,
- rec[i].ydim, rec[i].comp);
- printf("DFR8putimage return %d.\n", ret);
- firstImage = FALSE;
- }
- else {
- ret = DFR8addimage(fname, rec[i].img, rec[i].xdim,
- rec[i].ydim, rec[i].comp);
- printf("DFR8addimage return %d.\n", ret);
- }
- if (ret)
- printf("DFerror %d.\n", DFerror);
-
- printf("\n");
- }
- }
-
- void
- checkImages(fname, numImages)
- char *fname;
- int numImages;
- {
- int i, xdim, ydim, ispal, ret;
- char space[10000], pal[768];
- int all_ok = TRUE;
-
- for (i=0;i<numImages;i++) {
- printf("checkImages image %d.\n", i);
-
- ret = DFR8getdims(fname, &xdim, &ydim, &ispal);
- printf("DFR8getdims return %d.\n", ret);
- if (ret) {
- printf("DFerror %d.\n", DFerror);
- /* exit(1); */
- }
- printf("DFR8getdims %s, %d * %d, %d palette.\n", fname, xdim, ydim, ispal);
-
- if (rec[i].xdim != xdim){
- puts("xdim is wrong!!");
- all_ok = FALSE;
- }
- if (rec[i].ydim != ydim) {
- puts("ydim is wrong!!");
- all_ok = FALSE;
- }
- if ((ispal && (rec[i].pal == NULL)) ||
- (!ispal && (rec[i].pal != NULL))) {
- puts("ispal is wrong!!");
- all_ok = FALSE;
- }
-
- ret = DFR8getimage(fname, space, xdim, ydim, pal);
- printf("DFR8getimage return %d.\n", ret);
- if (ret) {
- printf("DFerror %d.\n", DFerror);
- /* exit(1); */
- }
-
- if (strncmp(space, rec[i].img, xdim * ydim)) {
- puts("Image is wrong!!");
- all_ok = FALSE;
- }
- if (ispal && strncmp(pal, rec[i].pal, PAL_SIZE)) {
- puts("Palette is wrong!!");
- all_ok = FALSE;
- }
- printf("\n");
- }
- if (all_ok == TRUE)
- printf("HDF HAS WRITTEN AND READ ALL %d IMAGES CORRECTLY.\n\n", numImages);
- }
-
- char *
- randArray(size)
- int size;
- {
- char *space;
- int i;
-
- space = (char *) malloc(size);
- if (space == NULL) {
- puts("--malloc error");
- exit(1);
- }
-
- for (i=0;i<size;i++)
- space[i] = (i*size)%256;
-
- return space;
- }
-
- int
- rndCompress(size)
- {
- switch(size%3) {
- case 0:
- return 0;
- break; /* for uniformity */
- case 1:
- return DFTAG_RLE;
- break;
- case 2:
- return DFTAG_IMC;
- break;
- }
- }
-